import { ref } from "vue";
import { computed } from "@vue/runtime-core";
export default function useFilteredTodos(todos){
   // 过滤逻辑
   const filterCondition = ref("all")
   const filteredTodos = computed(() => {
     switch (filterCondition.value) {
       case "done":
         return todos.value.filter((todo) => todo.completed);
       case "todo":
         return todos.value.filter((todo) => !todo.completed);
       default:
         return todos.value;
     }
   });

  // 切换条件  
  const changeFilterCondition = (event) => {
    // console.log(event) // 这里的event 是TodoFilter组件中emit返回的值
    filterCondition.value = event
  }
   
   return {
    filterCondition, 
    filteredTodos,
    changeFilterCondition
   }
}